<?php 

function option($items, $parent_id, $cat_id, $level=0) {
    foreach ($items as $item) {
        if ($item['id']==$cat_id) continue;
        
        $selected = ($item['id']==$parent_id) ? 'selected' : '';
        echo '<option value="'.$item['id'].'" '.$selected.'>';
        echo str_repeat('├─', $level).$item['name'];
        if (isset($item['children']) && is_array($item['children'])) {
            option($item['children'], $parent_id, $cat_id, $level+1);
        }
        echo '</option>';
    }
}
?>

<form action="" method="post" class="form-horizontal ajax-submit">

	<div class="form-group">
		<label class="col-sm-1 control-label">设备型号</label>
		<div class="col-sm-6">
			<input class="form-control" type="text" name="name" value="<?= $info['name'] ?>" required >	
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">设备品牌</label>
		<div class="col-sm-6">
<!--			<input class="form-control" type="text" name="brands" value="--><?//= $info['brands'] ?><!--" required >	-->
            <select name="brands" id="" class="form-control">
                <?php foreach ($device_brand as $d) :?>
                <option value="<?= $d['id']?>"><?= $d['name']?></option>
                <?php endforeach;?>
            </select>
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">设备类型</label>
		<div class="col-sm-6">
    		<select class="form-control" name="cid">
    		
    		<option value="0"> -选择设备类型- </option>
    			<?php if(Arr::get($_GET, 'pid')):?>
    			<?php option($cat_tree, Arr::get($_GET, 'pid'), 0);?>
    			<?php else:?>
    			<?php option($cat_tree, $info['cid'], $info['id']);?>
    			<?php endif;?>
    		
    		
            </select>
            
            
        </div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">设备图片</label>
		<div class="form-group ">
            <div id="works_pic_con">
            </div>
            <div id="works_pic_btn">
                <img  class="img-thumbnail" style="margin-left: 1%;"  src="/static/img/default.png"/>
            </div>
        </div>
	</div>
	
	
	<div class="form-group">
		<label for="address" class="col-sm-1 control-label"><i class="iconfont icon-dian color-blue"></i>地区</label>
		<div class="col-sm-10">
            <div class="form-group col-sm-2">
                <select class="form-control" id="province" name="province" required></select>
            </div>
            <div class="form-group col-sm-1"></div>

            <div class="form-group col-sm-2">
                <select class="form-control" id="city" name="city" required></select>
            </div>
            <div class="form-group col-sm-1"></div>
            <div class="form-group col-sm-2">
                <select class="form-control" id="area" name="area" required></select>
            </div>
			<!-- <input type="text" class="form-control " id="address"> -->
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">设备地址</label>
		<div class="col-sm-6">
			<input class="form-control" type="text" name="address" value="<?= $info['address'] ?>" required >
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">价格元/天</label>
		<div class="col-sm-2">
			<input class="form-control" type="text" name="price" value="<?= $info['price'] ?>" required >
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">设备描述</label>
		<div class="col-sm-6">
			<textarea name="desc" class="form-control" rows="4"><?= $info['desc'] ?></textarea>
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">设备配置</label>
		<div class="col-sm-11">
			<textarea id="editor" name="configuration"><?= htmlspecialchars($info['configuration'])?></textarea>
		</div>
	</div>
	
	
	<div class="form-group">
		<div class="col-sm-offset-1 col-sm-3">
			<button type="submit" class="btn btn-primary">提交</button>
		</div>
	</div>
</form>

<?php include DOCROOT.'/views/plupload.php';?>
<?= HTML::script('/static/js/jquery.city.js')?>
<script>
$(function(){
	//上传作品图片
    init_upload('works_pic_btn','works_pic_con','img',true);

	init_address('province', 'city', 'area');
})
</script>

<style>
.up-item{float:left;width:160px;margin:5px;position:relative}
.up-item .close{position:absolute;right:3px;top:0;}
.up-item .img-thumbnail{width:160px;}
.up-item .progress{position:absolute;left:0;bottom:0;width:100%;height:8px;margin:0;display:none}
</style>

<style>
div.mce-fullscreen {z-index: 9999;}
.mce-menubtn.mce-fixed-width span {width:auto}
</style>
<?= HTML::script('static/tinymce/tinymce.min.js')?>
<script type="text/javascript">
tinyMCE.init({
	selector : 'textarea#editor',
	plugins: [
		  		"advlist autolink lists link image charmap print preview anchor",
		  		"searchreplace visualblocks code fullscreen imagetools upload",
		  		"insertdatetime media table contextmenu paste textcolor colorpicker emoticons",
		  		"codesample eqneditor"
		  	],
  	toolbar: "upload undo redo | fontselect fontsizeselect forecolor | bold italic | link image emoticons | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | fullscreen preview",
  	autosave_ask_before_unload: false,
  	convert_urls: false,
    force_br_newlines : true,
    force_p_newlines : false,
    forced_root_block : '', // Needed for 3.x
	height : 400,
	content_css: ['<?= URL::site('static/css/preview.css')?>'],
	language: 'zh_CN'
});
</script>





